package com.decade.account.controller;

import com.decade.account.service.AccountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

/**
 * @Author: decade
 * @Description:
 * @Date: 2021/1/27 12:52
 **/
@RestController
@Slf4j
public class AccountController {
    @Autowired
    private AccountService accountService;

    @GetMapping("/decrease")
    public String decrease(Long userId, BigDecimal money) {
        if (Math.random() < 0.8) {
            throw new RuntimeException("模拟异常");
        }
        accountService.decrease(userId, money);
        return "用户账户扣减金额成功";
    }
}
